package com.yanqu.road.server.logic.activity.condition.shuihuyezicard;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.args.ValueParamArgs;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseNewRankActivityCondition;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigInteger;

/**
 * @Description 蜀山 最大仙力
 * @Author cwq
 * @Data 2021/12/16 15:38
 */
public class ShuiHuYeZiCardTotalCardLevelRankCondition extends BaseNewRankActivityCondition {
    public ShuiHuYeZiCardTotalCardLevelRankCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        // 卡牌总等级  和 积分
        ValueParamArgs valueParamArgs = (ValueParamArgs)object;
        BigInteger curTotalLevel = BigInteger.valueOf(valueParamArgs.getValue());
        if (curTotalLevel.compareTo(getValue()) > 0) {
            setValue(curTotalLevel);
        }
        long integral = Long.valueOf(valueParamArgs.getParam());
        long oldIntegral = 0;
        if(!StringUtils.isNullOrEmpty(getParam())){
            oldIntegral = Long.valueOf(getParam());
        }
        if(integral != oldIntegral){
            setParam(String.valueOf(integral));
            setModifyTime(DateHelper.getCurrentSecond());
        }
        rankChange();
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.ShuiHuYeZiCardTotalCardLevelRank.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.ShuiHuYeZiCardTotalCardLevelRank.getValue(), handle);
    }
}
